<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Thongbao_model extends CI_Model {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }

    public function load_thongbaogiasu($id) {
        $this->db->select('id');
        $this->db->where('thanhvien_id', $id);
        $this->db->where('LamGiaSu_TrangThai_id', 1);
        $lamgiasu = $this->db->get('gs7s_lamgiasu');
//        print_r($lamgiasu->result_array());
        $lamgiasu_id = NULL;
        $kq_thongbao = null;
        if ((count($lamgiasu->result_array(), COUNT_RECURSIVE) > 0)) {
            $i = 0;
            foreach ($lamgiasu->result_array() as $value) {
                $lamgiasu_id[$i] = $value['id'];
                $i = $i + 1;
            }
        }
//        print_r($lamgiasu_id);
        $i = 0;
        if ($lamgiasu_id != NULL) {
            foreach ($lamgiasu_id as $value) {
                $this->db->select('id,LamGiaSu_id,TrangThai,thanhvien_id');
                $this->db->where('LamGiaSu_id', $value);
                $lamgiasu_cho = $this->db->get('gs7s_lamgiasu_cho');
                //            echo "<br>";
                //            print_r($lamgiasu_cho->result_array());
                $j = 0;
                foreach ($lamgiasu_cho->result_array() as $value2) {
                    $this->db->select('id,tenhienthi');
                    $this->db->where('id', $value2['thanhvien_id']);
                    $thanhvien = $this->db->get('gs7s_thanhvien');
                    //                print_r($lamgiasu_cho->result_array()[$j]['LamGiaSu_id']);
                    //                print_r($thanhvien->result_array()[0]['tenhienthi']);
                    $kq_thongbao[$i + $j]['LamGiaSu_id'] = $lamgiasu_cho->result_array()[$j]['LamGiaSu_id'];
                    $kq_thongbao[$i + $j]['tenhienthi'] = $thanhvien->result_array()[0]['tenhienthi'];
                    $kq_thongbao[$i + $j]['thanhvien_id'] = $thanhvien->result_array()[0]['id'];
                    //                $lamgiasu_cho->result_array()[$j]['tenhienthi']=$thanhvien['tenhienthi'];
                    $j = $j + 1;
                }
                //            echo "<br>";
                $i = $i + $j;
            }
        }
         $kq_thongbao['id'] = $lamgiasu_id;
//        print_r($kq_thongbao);
        return $kq_thongbao;
    }

    public function load_thongbaolop($id) {
        $this->db->select('id');
        $this->db->where('thanhvien_id', $id);
        $this->db->where('TimGiaSu_TrangThai_id', 1);
        $timgiasu = $this->db->get('gs7s_timgiasu');
//        print_r($lamgiasu->result_array());
        $timgiasu_id = NULL;
        $kq_thongbao = NULL;
        if ((count($timgiasu->result_array(), COUNT_RECURSIVE) > 0)) {
            $i = 0;
            foreach ($timgiasu->result_array() as $value) {
                $timgiasu_id[$i] = $value['id'];
                $i = $i + 1;
            }
        }
//        print_r($lamgiasu_id);
        $i = 0;
        if ($timgiasu_id != NULL) {
            foreach ($timgiasu_id as $value) {
                $this->db->select('id,TimGiaSu_id,TrangThai,thanhvien_id');
                $this->db->where('TimGiaSu_id', $value);
                $timgiasu_cho = $this->db->get('gs7s_timgiasu_cho');
                //            echo "<br>";
                //            print_r($lamgiasu_cho->result_array());
                $j = 0;
                foreach ($timgiasu_cho->result_array() as $value2) {
                    $this->db->select('id,tenhienthi');
                    $this->db->where('id', $value2['thanhvien_id']);
                    $thanhvien = $this->db->get('gs7s_thanhvien');
                    //                print_r($lamgiasu_cho->result_array()[$j]['LamGiaSu_id']);
                    //                print_r($thanhvien->result_array()[0]['tenhienthi']);
                    $kq_thongbao[$i + $j]['TimGiaSu_id'] = $timgiasu_cho->result_array()[$j]['TimGiaSu_id'];
                    $kq_thongbao[$i + $j]['tenhienthi'] = $thanhvien->result_array()[0]['tenhienthi'];
                    $kq_thongbao[$i + $j]['thanhvien_id'] = $thanhvien->result_array()[0]['id'];
                    //                $lamgiasu_cho->result_array()[$j]['tenhienthi']=$thanhvien['tenhienthi'];
                    $j = $j + 1;
                }
                //            echo "<br>";
                $i = $i + $j;
            }
        }
        $kq_thongbao['id'] = $timgiasu_id;
        return $kq_thongbao;
    }

}

?>
